function Haaway(){
	this.version = '1.0.0';
	this.author = 'HAAWAY STUDIO';
	this.updatetime = '2011年4月12日';
	
	this.userinfo = {};
	this.options = {
		apiUrl : '/index.php'
	};
	this.flag = {};
	this.appPath = this.getAppPath();
	

	this.init = function(){
		$hw.include([ $hw.appPath + 'themes/default/config.js']);
	};


	/** 动态加载一个或一组js/css文件 */
	this.flag.included = {};
	this.include = function(urls) {
		var cache = this.flag.included;
		var extension = extension || false;
		if (typeof urls === "string")
			urls = [urls];

		var jsfile = new Array();
		for (i = 0; i < urls.length; i ++) {
			var url = urls[i];
			if (typeof url !== "string") continue;

			// 防止重复加载
			if(cache[url]) continue;
			cache[url] = true;

			var extension = url.split('.')[url.split('.').length-1];
			if(extension == 'css')
				document.write('<link type="text/css" rel="stylesheet" href="' + url + '" />');
			if(extension == 'html')
				this.htmls.push(this.get(url));
			else if(extension == 'js')
				jsfile.push(url);
			else
				document.write('<script src="' + url + '"></script>');
		}
		for (i = 0; i < jsfile.length; i ++)
				document.write('<script src="' + jsfile[i] + '"></script>');
	};
	//ajax处理重写
	this.load = function(m, c, p, callback){
		var purl = this.options.apiUrl + '?m='+m+'&a='+c+'&inajax=1',
			result = false;
		p= p || {};
		
		$.ajax({
			async: callback ? true : false,
			timeout: 150000,
			type: 'POST',
			url: purl,
			data: p,
			datatype: "json",
			beforeSend :function(XMLHttpRequest){
				//if(beforesend) beforesend();
			},
			success: function(json) {
				
				if (typeof json === "string") {
					
					if (json.length < 1) {
						this.growl('json无效，数据为空');
						return;
					}

					result = $.parseJSON(json);

				} else {					
					result = json;
				}

				if (result != null && result.status == 0) {
					//this.showError(result.code, [result.message]);
					result = false;
				} else {
					if (callback) callback(result);					
				}
			}

		});//end of jquery ajax



	};

	/**
	 * 弹出消息
	 */
	this.growlo = function(message) {		
		var g = $('#one_jgrowl');
		if (g.length == 0)
			g = $('<div id="one_jgrowl" class="jGrowl bottom-right"></div>').appendTo('body');
		
		$('#one_jgrowl').jGrowl(message);
	};
	this.growl = function(message){
		$.jGrowl(message);
	}

}

Haaway.prototype = {
	getAppPath	: function(){		
		return '/public/';
	},
	
	/**
	 * 信息提示
	 */
	alert: function(message, callback, width, height, title) {
		title = title || '信息提示';
		ymPrompt.alert(message, width, height, title, callback);
	},

	/**
	 * 成功信息提示
	 */
	succeed: function(message, callback, width, height, title) {
		title = title || '操作成功';
		ymPrompt.succeedInfo(message, width, height, title, callback);
	},

	/**
	 * 保存成功的信息提示
	 */
	saved: function(message, callback, width, height, title, btn) {
		message = message || '保存数据成功！';
		title = title || '操作成功';
		btn = btn || [['返回列表','list'],　['继续添加','add']];
		ymPrompt.succeedInfo({message: message, width: width, height: height, title: title, handler: callback, btn: btn});
	},

	/**
	 * 失败信息提示
	 */
	error: function(message, callback, width, height, title) {
		title = title || '操作失败';
		ymPrompt.errorInfo(message, width, height, title, callback);
	},

	/**
	 * 询问信息
	 */
	confirm: function(message, callback, width, height) {
		ymPrompt.confirmInfo(message, width, height,'信息提示', callback)
	},

	/**
	 * 弹出窗
	 * @param	message	文本/iframe模式的URL
	 * @param	width	宽
	 * @param	height	高
	 * @param	title	标题
	 * @param	callback	回调
	 * @param	iframe		为空则为普通模式，否则填iframe的属性，示例：{id: 'iframe01'}
	 * @param	btn			自定义按钮，示例:[['是','yes'],['否','no'],['取消','cancel']]})
	 **/
	win: function(message, width, height, title, callback, iframe, btn, showmask) {
		ymPrompt.win({message: message, width: width, height: height, title: title, handler: callback, iframe: iframe, btn: btn, showMask: showmask});
		return ymPrompt;
	}
}
	
var $hw = new Haaway();
$hw.init();


	document.write('<link type="text/css" rel="stylesheet" href="' + $hw.appPath + 'lib/blackbirdjs/blackbird.css" />');
	document.write('<link type="text/css" rel="stylesheet" href="' + $hw.appPath + 'lib/ymPrompt/skin/simple_gray/ymPrompt.css" />');
	document.write('<link type="text/css" rel="stylesheet" href="' + $hw.appPath + 'lib/jgrowl/jquery.jgrowl.css" />');

$hw.include([
		//$hw.appPath + 'js/ui/jquery.ui.widget.js',
		//$hw.appPath + 'js/common.js',
		//$hw.appPath + 'js/json2.min.js',
		//$hw.appPath + 'js/jquery.metadata.js',
		//$hw.appPath + 'js/jquery.sprintf.js',
//		$hw.appPath + 'js/ui/jquery.ui.widget.js',
	//	$hw.appPath + 'js/jtemplates/jquery-jtemplates.js',

		// JS调试工具，在浏览器按F2查看
		$hw.appPath + 'lib/blackbirdjs/blackbird.js',

		// flexigrid
		//$hw.appPath + 'js/flexigrid/jquery.flexigrid.js',
		// 表格右键菜单
		//$hw.appPath + 'js/ContextMenu/jquery.contextMenu.js',

		// 弹出窗
		$hw.appPath + 'lib/ymPrompt/ymPrompt.js',

		// 提示
		$hw.appPath + 'lib/jgrowl/jquery.jgrowl_minimized.js',

		// 搜索面板
		//$hw.appPath + 'css/lib/jkmenu/jkmegamenu.js',
		//系统菜单控制
		//$hw.appPath + 'css/lib/jkmenu/jkmegamenuOld.js',

		// 自动完成
		//$hw.appPath + 'js/acbox/js/jquery.ajaxComboBox.3.5.7.js',

		// Tree
//		$hw.appPath + 'js/plugin/jquery.tree.js'
	]);

